package com.tbit.uqbike.webmanager.util.csv.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;

import java.io.*;
import java.util.Date;

/**
 * 基础实体
 *
 * @Author HZW
 * @ClassName BaseEntity
 * @Description
 * @date 2022/10/22 16:05
 * @Version 1.0
 */
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Data
@Slf4j
public class CsvBaseEntity implements Serializable {
    /**
     * 开始时间
     */
    private Date startTime;
    /**
     * 结束时间
     */
    private Date endTime;

    /**
     * 开始的id
     * */
    private Integer startId;

    /**
     * 结束的id
     * */
    private Integer endId;
    public CsvBaseEntity(Date startTime, Date endTime){
        this.startTime = startTime;
        this.endTime = endTime;
    }

    public CsvBaseEntity(Integer startId, Integer endId){
        this.startId = startId;
        this.endId = endId;
    }


    /**
     * 克隆
     *
     * @return {@link CsvBaseEntity}
     */
    @Override
    public CsvBaseEntity clone() {
        CsvBaseEntity csvBaseEntity = null;
        try {
            // 写入字节流
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(stream);
            oos.writeObject(this);

            ByteArrayInputStream bais = new ByteArrayInputStream(stream.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bais);
            csvBaseEntity = (CsvBaseEntity) ois.readObject();
        } catch (ClassNotFoundException | IOException e) {
            log.error(e.getMessage(), e);
        }
        return csvBaseEntity;
    }
}
